from fastapi import FastAPI
import asyncio

from .core.exception import register_exceptions
from .routes import items, users
from .core.db import init_db

# 创建 FastAPI 应用实例
app = FastAPI()

init_db(app)  # 初始化 ORM

# 注册异常处理器
register_exceptions(app)

# 注册 API 路由
app.include_router(items.router, prefix="/api")
app.include_router(users.router, prefix="/api")


# 定义 API 端点
@app.get("/")
def read_root():
    return {"message": "🚀 System is running, FastAPI!"}


@app.get("/async")
async def async_example():
    await asyncio.sleep(2)  # 模拟异步任务
    return {"message": "异步任务完成！"}
